package other.mvvm.activity.src.app_package.login

import com.android.tools.idea.wizard.template.ModuleTemplateData
import com.android.tools.idea.wizard.template.RecipeExecutor
import com.android.tools.idea.wizard.template.impl.activities.common.generateManifest
import other.mvvm.activity.res.layout.login.colorsXml
import other.mvvm.activity.res.layout.login.loginActivityXml
import other.mvvm.activity.res.layout.login.stringsXml
import other.mvvm.activity.res.layout.login.stylesXml
import java.io.File

fun RecipeExecutor.loginActivityRecipe(
        moduleData: ModuleTemplateData,
        activityClass: String,
        layoutName: String,
        packageName: String
) {
    val (projectData, srcOut, resOut) = moduleData
    val ktOrJavaExt = projectData.language.extension
    generateManifest(
            moduleData = moduleData,
            activityClass = "${activityClass}Activity",
            packageName = packageName,
            isLauncher = false,
            hasNoActionBar = false,
            generateActivityTitle = true
    )

   //copy(File("edit_input.xml"), resOut.resolve("drawable/edit_input.xml"))
    //copy(File("btn_normal.xml"), resOut.resolve("drawable/btn_normal.xml"))


    val mvvmActivity = loginAcitivityKt(projectData.applicationPackage, activityClass, packageName)
    // 保存Activity
    save(mvvmActivity, srcOut.resolve("${activityClass}Activity.${ktOrJavaExt}"))
    // 保存xml
    save(loginActivityXml(), resOut.resolve("layout/${layoutName}.xml"))
    // 保存viewmodel
    save(loginViewModel(packageName, activityClass), srcOut.resolve("${activityClass}ViewModel.${ktOrJavaExt}"))
    // 保存repository
    save(loginRepository(packageName, activityClass), srcOut.resolve("${activityClass}Repository.${ktOrJavaExt}"))

    mergeXml(colorsXml(), resOut.resolve("values/colors.xml"))
    mergeXml(stringsXml(), resOut.resolve("values/strings.xml"))
    mergeXml(stylesXml(), resOut.resolve("values/styles.xml"))
}